﻿<%@ WebHandler Language="C#" Class="hUserGroup" %>
using System;
using System.Web;
using System.Data;
using System.Collections.Generic;
using System.Web.SessionState;
using BLL.System;
using CommonLib;


public class hUserGroup : IHttpHandler, IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        handle(context);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
    private void handle(HttpContext context)
    {
        string action = context.Request.QueryString["action"];
        string result = string.Empty;
        int? pageSize = null;
        if (!string.IsNullOrEmpty(context.Request["rows"])) pageSize = Convert.ToInt32(context.Request["rows"]);
        int? pageNum = null;
        if (!string.IsNullOrEmpty(context.Request["rows"])) pageNum = Convert.ToInt32(context.Request["page"]);
        Dictionary<string, string> dicLike = new Dictionary<string, string>();
        Dictionary<string, string> dicEqual = new Dictionary<string, string>();
        try
        {
            if (context.Session["user"] == null) throw new Exception("登录超时！");
            UserGroupBO bo = new UserGroupBO();
            UserBO ubo = new UserBO();
            switch (action)
            {

                case "get":
                    if (context.Request["userkey"] != null) dicEqual.Add("ug.USER_KEY", context.Request["userkey"]);
                    result = bo.getUserGroup(dicLike, dicEqual, pageSize, pageNum);
                    break;

                case "getuser":
                    if (context.Request["sUSERName"] != null) dicLike.Add("u.USER_NAME", context.Request["sUSERName"]);
                    if (!string.IsNullOrEmpty(context.Request["q"]))
                    {
                        dicLike["attachCondition"] = string.Format("u.USER_NAME like '%{0}%' or u.USER_ID like '%{0}%' ", context.Request["q"]);
                        //dicLike["u.USER_ID"] = context.Request["q"];
                    }
                    if (context.Request["sUSERID"] != null) dicLike.Add("u.USER_ID", context.Request["sUSERID"]);

                    result = ubo.getUser(context, dicLike, dicEqual, pageSize, pageNum);
                    break;
                case "add":
                    //
                    result = bo.addUserGroup(context);
                    break;
                case "adduser":
                    //
                    result = ubo.addUser(context);
                    break;
                case "edituser":
                    //
                    result = ubo.editUser(context);
                    break;
                case "deluser":
                    //
                    result = ubo.delUser(context);
                    break;

                case "del":
                    //删除
                    result = bo.delUserGroup(context);
                    break;
                case "loginlog":
                    ubo.addLoginLog(context);
                    break;


            }
        }
        catch (Exception ex)
        {
            var error = new Entities.Status { Success = false, Message = ex.Message };
            result = error.ToJson();

        }
        finally
        {
            context.Response.Write(result);
        }
    }


}
